using MeetingManagement.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace MeetingManagement.Infrastructure.EntityConfigurations;

public class MeetingConfiguration : IEntityTypeConfiguration<Meeting>
{
    public void Configure(EntityTypeBuilder<Meeting> builder)
    {
        builder.HasKey(m => m.Id);

        builder.Property(m => m.Title)
            .IsRequired()
            .HasMaxLength(100);

        builder.Property(m => m.Description)
            .HasMaxLength(500);

        builder.Property(m => m.Location)
            .HasMaxLength(100);

        builder.Property(m => m.Status)
            .IsRequired();

        builder.HasOne(m => m.MeetingRoom)
            .WithMany(r => r.Meetings)
            .HasForeignKey(m => m.MeetingRoomId)
            .IsRequired(false)
            .OnDelete(DeleteBehavior.SetNull);
    }
}
